package com.sso.manager;

import com.sso.entity.SysAccessControl;
import com.sso.exception.SelectException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysAccessControlManager implements BaseManager<SysAccessControl> {
    @Override
    public int save(SysAccessControl entity) throws Exception {
        return 0;
    }

    @Override
    public List<SysAccessControl> selectByPage(Map<String, Object> param){
        return null;
    }

    @Override
    public List<SysAccessControl> selectByProperty(Map<String, Object> param){
        return null;
    }

    @Override
    public long countByProperty(Map<String, Object> param) {
        return 0;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public SysAccessControl selectBySysEname(String sysEname) throws SelectException {
        Map<String,Object> param = new HashMap<String, Object>();
        param.put("sysEname",sysEname);
        SysAccessControl operationSystemControl = this.selectByUnique(param);
        return operationSystemControl;
    }

    /**
     * 唯一字段查询
     * @param param
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS)
    public SysAccessControl selectByUnique(Map<String,Object> param) throws SelectException {
        List<SysAccessControl> list = this.selectByProperty(param);
        if(list.size()==0){
            return new SysAccessControl();
        }
        if(list.size()>1){
            throw new SelectException("唯一查询错误，集合大小为："+list.size());
        }
        return list.get(0);
    }
}
